import React from "react";
import { observable } from "mobx";
import { message } from "antd";
import a from "../../component/Xf/Zxdg/Zxdg";
import axios from "axios";
const { MyBtn } = a;
class hpStore {
  @observable.ref columns = [
    {
      title: "文章标题",
      dataIndex: "title",
    },
    {
      title: "栏目",
      dataIndex: "lb",
    },
    {
      title: "关联楼盘",
      dataIndex: "gllp",
    },
    {
      title: "编辑",
      dataIndex: "bj",
    },
    {
      title: "浏览量",
      dataIndex: "lll",
    },
    {
      title: "状态",
      dataIndex: "zt",
    },
    {
      title: "发布时间",
      dataIndex: "time",
    },
  ];
  @observable.ref shArr = [];
  @observable.ref data = [];
  // 请求初始数据
  getData = () => {
    axios.defaults.baseURL = "http://101.37.175.158:6789";
    // axios.defaults.baseURL = "/hp";
    return axios({
      url: "/getFc",
      method: "get",
    }).then((res) => {
      if (this.columns[7] === undefined) {
        this.publicMethod(this.columns);
      }
      let data = res.data.filter((item) => {
        item.time = item.time.slice(0, 10);
        item.key = item.id;
        return item;
      });
      // console.log(data)
      this.data = data;
    });
  };
  // 删除
  myDel = (id) => {
    let a = [...this.data];
    a.splice(id - 1, 1);
    this.data = a;
  };
  Edit = (record) => {
    console.log(record);
  };
  // 添加操作列
  publicMethod = (arr) => {
    arr.push({
      title: "操作",
      dataIndex: "action",
      align: "center",
      render: (text, record) => (
        <MyBtn
          data={record.key}
          rowdata={record}
          myDel={this.myDel}
          myEdit={this.Edit}
        />
      ),
    });
    return arr;
  };
  // 批量审核
  allSh = () => {
    // console.log(this.shArr)
    if (this.shArr.length === 0) {
      message.warning("请先选择可以修改的数据！");
    }
    let aaa = [...this.data];
    aaa.filter((item) => {
      if (this.shArr.includes(item.key)) {
        if (item.zt === "等待审核") {
          item.zt = "通过审核";
          message.success("操作成功！");
        }
      }
      return item;
    });
    this.data = aaa;
  };
  // 是否被选中
  addShArr = (selectedRowKeys) => {
    this.shArr = selectedRowKeys;
  };
  // 下拉框搜索
  xz2 = (value, name) => {
    console.log(value);
    let ccc = "";
    name === "ztValue" ? (ccc = "zt") : (ccc = "lb");
    let aaa = [...this.data];
    let bbb = [];
    aaa.filter((item) => {
      if (item[ccc] === value) {
        bbb.push(item);
      }
      return item;
    });
    this.data = bbb;
  };
  // 输入框搜索
  selTAN = (value, type) => {
    // console.log(value, type);
    let ccc = "";
    type === "title" ? (ccc = "title") : (ccc = "gllp");
    let aaa = [...this.data];
    let bbb = [];
    aaa.filter((item) => {
      if (item[ccc] === value) {
        bbb.push(item);
      }
      return item;
    });
    this.data = bbb;
  };
}
export default hpStore;
